<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <%@include file="../_static/_head.jsp"%>
</head>
<body>
<div class="layui-card">
    <nav class="breadcrumb"><a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
    <div class="layui-card-header">新闻列表</div>
    <div class="layui-card-body">
        <script type="text/html" id="dataOperator">
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="update">修改</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
        </script>
        <div class="operator">
            <a class="layui-btn layui-btn-normal" href="javascript:void(0);" onclick="add('新增新闻','/information/news/add.html')" id="adda">新增新闻</a>
        </div>

        <table id="dataTable" lay-filter="tabFilter"></table>

        <script type="text/html" id="stateTpl">
            {{#  if(d.state == 0){ }}
            <button class="layui-btn layui-btn-danger layui-btn-radius layui-btn-xs">禁用</button>
            {{#  } else { }}
            <button class="layui-btn layui-btn-warm layui-btn-radius layui-btn-xs">启用</button>
            {{#  } }}
        </script>

        <script type="text/html" id="imgTpl">
            <img src='{{d.titleImg}}'>
        </script>

    </div>
</div>

<script src="<%=basePath%>plugins/layui/layui.js"></script>
<script src="<%=basePath%>plugins/dateformat.js"></script>
<script>
    layui.use(['layer', 'form','table','laydate'], function() {
        var form = layui.form,table = layui.table,laydate = layui.laydate,
            $ = layui.jquery;

        var tableIns = table.render({
            elem: '#dataTable'
            ,id:'dataTab'
            ,url: '/information/news/list.json'
            ,page: true
            ,cols: [[
                {field: 'id', title: 'ID', width:80, fixed: 'left'}
                ,{field: 'title', title: '名称'}
                ,{field: 'titleImg', title: '标题图片',templet: '#imgTpl'}
                ,{field: 'createTime', title: '创建时间'}
                ,{field: 'sort', title: '排序'}
                ,{fixed: 'right', title:'操作',width:200, align:'center', fixed: 'right',toolbar: '#dataOperator'}
            ]]
        });

        table.on('tool(tabFilter)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象

            if(layEvent === 'update'){ //查看
                var index = layer.open({
                    type: 2,
                    title: "修改权限菜单信息",
                    content: "/sys/menu/update.html?id="+data.id
                });
                layer.full(index);
            } else if(layEvent === 'delete'){ //删除
                layer.confirm('确定删除该行数据么，该行下面的子菜单也会一并删除', function(index){
                    $.ajax({
                        url: "/sys/menu/delete.json",
                        data:{id:data.id},
                        method:"POST",
                        success: function(data){
                            if (data.code==200){
                                location.reload();
                            } else{
                                layer.msg(data.msg,{icon:2,time:1000});
                            }
                        }});
                });
            } else if(layEvent === 'permission'){
                var index = layer.open({
                    type: 2,
                    title: "页面列表",
                    content: "/sys/menu/page/index.html?id="+data.id
                });
                layer.full(index);
            }
        });
    });

    function add(title,url){
        var index = layer.open({
            type: 2,
            title: title,
            content: url
        });
        layer.full(index);
    }
</script>
</body>
</html>
